//
//  MyCollectionViewCell.m
//  LZMPro
//
//  Created by dllo on 15/11/5.
//  Copyright © 2015年 LZS. All rights reserved.
//

#import "MyCollectionViewCell.h"
#import "MovieModel.h"
#import <UIImageView+WebCache.h>
#import "UIView+Frame.h"

@implementation MyCollectionViewCell



-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    
    if (self) {
        
        [self createSubViews];
    }
    
    return self;
}


-(void)createSubViews{
    //底为透明
    self.backgroundColor = [UIColor clearColor];
    self.contentView.backgroundColor = [UIColor clearColor];
    
    //scrollView
    self.myscrollView = [[UIScrollView alloc] initWithFrame:self.contentView.frame];
    self.myscrollView.height = 300;
    
    self.myscrollView.contentSize = CGSizeMake(CURRENTWIDTH, 0);
    [self.contentView addSubview:self.myscrollView];
    
    //图片
    self.myImageview = [[UIImageView alloc]initWithFrame:self.contentView.frame];
    self.myImageview.height = 300;
    [self.myscrollView addSubview:self.myImageview];
    self.myImageview.userInteractionEnabled = YES;
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(click)];
//    [self.myImageview addGestureRecognizer:tap];
    [self addanimation];
    
    //点击
    self.clickView = [[UIView alloc] initWithFrame:self.contentView.frame];
    self.clickView.height = 300;
    [self.myscrollView addSubview:self.clickView];
    [self.clickView addGestureRecognizer:tap];

    
    self.swipView = [[UIView alloc] initWithFrame:CGRectMake(0, 300, CURRENTWIDTH, 300)];
    [self.contentView addSubview:self.swipView];
    UISwipeGestureRecognizer *swipeGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swippeGesture)];
    //设置轻扫的方向:向上
    swipeGesture.direction = UISwipeGestureRecognizerDirectionUp;
    [self.swipView addGestureRecognizer:swipeGesture];
    
}

-(void)click
{
    [self.mydelegate  didSelectCollection:self.index];
}

-(void)swippeGesture{
    [self.mydelegate CellSwippeGesture];
}



-(void)setModel:(MovieModel *)model
{
    _model = model;
    
   
    [self.myImageview sd_setImageWithURL:[NSURL URLWithString:model.coverForDetail]];

}

-(void)addanimation{
    [UIView animateKeyframesWithDuration:30.f delay:2 options:UIViewKeyframeAnimationOptionRepeat animations:^{
        
        [UIView addKeyframeWithRelativeStartTime:0 relativeDuration:1/ 2.0 animations:^{
            
//            self.myImageview.frame = CGRectMake(-50, 0, 475, 330);
            self.myImageview.transform = CGAffineTransformScale(self.myImageview.transform, 1.2, 1.2);
            
        }];
        
        [UIView addKeyframeWithRelativeStartTime:1/2.0 relativeDuration:1/ 2.0 animations:^{
            
//            self.myImageview.frame = CGRectMake(-25, 0, 425, 315);
//            self.myImageview.frame = CGRectMake(0, 0, 375, 300);
            self.myImageview.transform = CGAffineTransformScale(self.myImageview.transform, 1/ 1.2, 1/ 1.2);
            
        }];
        
    } completion:^(BOOL finished) {
        
    }];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
